/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;


import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author student
 */
public class JNotatnikForm extends javax.swing.JFrame {

    /**
     * Creates new form JNotatnikForm
     */
    public JNotatnikForm() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea = new javax.swing.JTextArea();
        jMenuBar = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        new_jmi = new javax.swing.JMenuItem();
        open_jmi = new javax.swing.JMenuItem();
        save_jmi = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        exit_jmi = new javax.swing.JMenuItem();
        jMenuEdit = new javax.swing.JMenu();
        jMenuFormat = new javax.swing.JMenu();
        wrapText_cbmi = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JNotatnik 0.1");

        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        jTextArea.setColumns(20);
        jTextArea.setRows(5);
        jScrollPane1.setViewportView(jTextArea);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jMenuFile.setText("File");

        new_jmi.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        new_jmi.setText("Nowy");
        new_jmi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                new_jmiActionPerformed(evt);
            }
        });
        jMenuFile.add(new_jmi);

        open_jmi.setText("Otworz");
        open_jmi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                open_jmiActionPerformed(evt);
            }
        });
        jMenuFile.add(open_jmi);

        save_jmi.setText("Zapisz");
        save_jmi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                save_jmiActionPerformed(evt);
            }
        });
        jMenuFile.add(save_jmi);
        jMenuFile.add(jSeparator1);

        exit_jmi.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, java.awt.event.InputEvent.ALT_MASK));
        exit_jmi.setText("Koniec");
        exit_jmi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exit_jmiActionPerformed(evt);
            }
        });
        jMenuFile.add(exit_jmi);

        jMenuBar.add(jMenuFile);

        jMenuEdit.setText("Edit");
        jMenuBar.add(jMenuEdit);

        jMenuFormat.setText("Format");

        wrapText_cbmi.setText("zawijaj wiersze");
        wrapText_cbmi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wrapText_cbmiActionPerformed(evt);
            }
        });
        jMenuFormat.add(wrapText_cbmi);

        jMenuBar.add(jMenuFormat);

        setJMenuBar(jMenuBar);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void save_jmiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_save_jmiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_save_jmiActionPerformed

    private void new_jmiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_new_jmiActionPerformed
        //aaa
        int odp = JOptionPane.showConfirmDialog(this, "Chcesz stracic to co napisałeś?");
        //komentarz
        //inny nowy komentarz
        //komentarz ciąg dalszy
        //aaaa
        
        //test 
        // test 
        //test
    }//GEN-LAST:event_new_jmiActionPerformed

    private void exit_jmiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exit_jmiActionPerformed
         dispose();
        
    }//GEN-LAST:event_exit_jmiActionPerformed

    private void open_jmiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_open_jmiActionPerformed
       int returnVal = jfChooser.showOpenDialog(this);
       if(returnVal == JFileChooser.APPROVE_OPTION) {            
            choosenFile = jfChooser.getSelectedFile();
            try {
                StringBuilder createdText = new StringBuilder();
                BufferedReader reader = new BufferedReader(new FileReader(choosenFile));
                while(reader.ready()){
                    String line = reader.readLine();
                    createdText.append(line+'\n');
                }
                createdText.delete(createdText.length()-1, 
                                    createdText.length());
                jTextArea.setText(createdText.toString());
            } catch (FileNotFoundException ex) {
                
            } catch (IOException ioe){
                
            }
            
       }//if wybrano plik
        
        
        
    }//GEN-LAST:event_open_jmiActionPerformed

    private void wrapText_cbmiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wrapText_cbmiActionPerformed
         jTextArea.setLineWrap(wrapText_cbmi.isSelected());
        
    }//GEN-LAST:event_wrapText_cbmiActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JNotatnikForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JNotatnikForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JNotatnikForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JNotatnikForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new JNotatnikForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem exit_jmi;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenu jMenuEdit;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenu jMenuFormat;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTextArea jTextArea;
    private javax.swing.JMenuItem new_jmi;
    private javax.swing.JMenuItem open_jmi;
    private javax.swing.JMenuItem save_jmi;
    private javax.swing.JCheckBoxMenuItem wrapText_cbmi;
    // End of variables declaration//GEN-END:variables
    private JFileChooser jfChooser = new JFileChooser();
    private File choosenFile = null;
}
